export const loadScript = ({ src, xml, container }) => {
    return new Promise(resolve => {
        const script = document.createElement("script");
        script.src = src;
        script.onload = function () {
            render(xml, container, () => {
                resolve();
            });
        };
        document.body.appendChild(script);
    });
}

export const addSpot = (hs_name, h, v, url, onlick) => {
    krpano.call("addhotspot(" + hs_name + ")");
    krpano.set("hotspot[" + hs_name + "].url", url);
    krpano.set("hotspot[" + hs_name + "].ath", h);
    krpano.set("hotspot[" + hs_name + "].atv", v);
    krpano.set("hotspot[" + hs_name + "].onclick", function () {
        onlick();
    });

}

function render(xml, container, callback) {
    const div = document.createElement("div");
    div.id = "krpano";

    container.appendChild(div);
    embedpano({
        xml: xml,
        target: div.id,
        onready: callback
    });
}
